<?php

/**
 * @author edson
 * @copyright 2011
 */

class CDrawPage {
    
    
    public static $instance;
    function  DrawHead($action,$name,$method,$NAME){echo "<div id='register-box'>\n";echo "<form action='$action' method='$method' name='$name'>\n";echo "<h2>$NAME</h2>\n";}
    function  DrawFoot(){
        echo "</form>";
        echo "</div>";}
    function  DrawTextBox()
    {
        $table=func_get_args();
        //echo $table[0];
        if(count(func_get_args())>1){
            ?>
                <p>
                <?php
                    $items=func_get_args();
                    $items=$items['0'];
                    foreach($items as $id => $valor)
                    {
                        echo "<input type='hidden'  name='$valor' value='$id'>";
                        
                    }
               
                ?>
               
                </p> 
            
        
        
                <?php
            return ;
            }
        else{
        ?>
               <p>
               <?php
               $items=func_get_args();
                    $items=$items['0'];
                    foreach($items as $id => $valor)
                    {
                        echo "<label>".$valor."<input type='text' name='$valor' class='general-textarea'>"."</label>";
                        
                    }
               
               ?>
               
               </p> 
            
        
        
        <?php
        return ; 
        }
    }
    function DrawSelect($table,$campos,$NAME)//especificar los campos que deben de aparecer 
    {
        
        $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;
        
        $table2=CModelo::getInstance()->getData($query);
        //var_dump($table2);
        ?>
        
        
        <label><?php echo $NAME;?>
        <select>
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;$select="";$i=0;
        //echo var_dump($tabla);
        foreach($tabla as $campo=>$valor)
        {
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            if($i<=0){$select=$select."<option value=".$valor."> ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo].",";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select>       
        </label>
        
    
    <?php
    }
    
    /*****dibuja <input > en html checkbox *****************/
    
    function DrawCheckBox($items)
    {
        echo "<p >";
      
      
      foreach($items as $id => $valor)
                    {
                        echo "<label>".$id."<input class=\"input-checkboxes\" type=\"checkbox\" name='$id' value='$valor'>"."</label>\n";
                        
                    }
      
      echo "</p>";
        
    }
    
    /*******************************************************/
    /*****dibuja <input > en html radiobutton *****************/
    
    function DrawRadioButton($items)
    {
      
      echo "<p >";
      
      
      foreach($items as $id => $valor)
                    {
                        echo "<label>".$id."<input class=\"input-radio\" type=\"radio\" name='$id' value='$valor'>"."</label>\n";
                        
                    }
      
      echo "</p>";
      
        
        
    }
    /******************************************/
    
    
    /*****dibuja <div> en html*****************/ 
    
    function DrawDivBegin()// si el parametro contiene 1 se dibuja una division de tipo display:none
    {   //var_dump(func_get_args());
         $table=func_get_args();
        //echo $table[0];
        if(count(func_get_args())>1){
            $colum=func_get_args();
            //foreach($colum as $id => $valor)
            //{
                echo "<div id='$colum[0]' >";
            //}
            return ;}
            $colum=func_get_args();
        echo "<div id='$colum[0]'>";
    }
    function DrawDivEnd()
    {echo "</div>";}
    
    function DrawDivUi($id){
    }
    /****************************************/
    
    
    
    /*****dibuja <form> en html*****************/
    
    function DrawFormBegin($action,$name,$method,$NAME="")
    {
        echo "<form action='$action' method='$method' name='$name'>\n";echo "<h2>$NAME</h2>\n";
        
    }
    function DrawFormEnd(){echo  "</form>";}
    
    
    /*----------------------------------------*/
    //
    //   FUNCION LISTADO
    //
    /*----------------------------------------*/
    
    function DrawListado($vars)
    {
        


        ?>

        <div class="pagination">
        <?php


	
	

        ?>
        <br class="clearfloat" />
        </div>
            <?php
} // end of pagination check if statement 
    
    function __construct()
    {
        
        
    }
    
    public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new CDrawPage();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	
    
}

?>